﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 应用
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var see1 = Session["UserInfo"];

            if(see1 !=null && string.IsNullOrEmpty(see1.ToString()))
            {
                Response.Redirect("Default.aspx");
            }
        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var username = Login1.UserName;

            var password = Login1.Password;

            var sql = string.Format("select * from Users where Username = '{0}' and Password = '{1}'",username,password);

            var users = Dbhelper.GetDatatable(sql);

            if (users.Rows.Count > 0)
            {
                Session["UserInfo"] = username;
                Session["UserId"] = users.Rows[0].ItemArray[0].ToString();

                Response.Redirect("Default.aspx");
            }
        }
    }
}